from hep.aida import *

from java.awt import Color
from java.awt import Font
from java.lang import *
from java.util import *
from java.io import *

from jhplot.jadraw import *
from jhplot  import *

from fr.in2p3.ipnl.aidautilities import *
from fr.in2p3.ipnl.oflap.scint import *
from jscinttools.jhplotutilities import *

Locale.setDefault(Locale.ENGLISH)
System.getProperties().setProperty("hep.aida.BatchAnalysisFactory","hep.aida.ref.BatchAnalysisFactory")

showFigures = False
writeFigures = not showFigures

""" Define colors and fonts """
figType = [".png", ".eps"]
colors = [Color.blue, Color.red, Color(0, 170, 0), Color.magenta, Color.black, Color.yellow]
axisLabelFont = Font(Font.SERIF, Font.PLAIN, 25)
titleFont = Font(Font.SERIF, Font.PLAIN, 25)
legendFont = Font(Font.SERIF, Font.PLAIN, 20)
ticFont = Font(Font.SERIF, Font.PLAIN, 20)
statBoxFont = Font(Font.SERIF, Font.PLAIN, 15)

""" Define the Path and files names """
aidaPathL = "/home/marc-antoine/Documents/BGO/QFin"
aidaFileL = "ScintillationAnalysis_BGO"
              
aidaPathQ = "/home/marc-antoine/Documents/BGO/QFin/QueensData/queenstools"
aidaFileQ = "ScintillationAnalysis_BGO_QFile"
              
outPath = "/home/marc-antoine/Dropbox/BGO"

treeL = AidaFileReader(aidaPathL, aidaFileL).tree
treeQ = AidaFileReader(aidaPathQ, aidaFileQ).tree

		
	
lyCorrL = P1D(GrabIObject(treeL, "/Light_Yield/LY Corr").dps)
lyCorrL.title = "BGO-L (&gamma;)"
lyCorrL.style = "p"
lyCorrL.symbol = 6
lyCorrL.symbolSize = 12
lyCorrL.color = colors[0]
lyCorrL.errY = True
lyCorrL.errX = False
lyCorrL.errColor = lyCorrL.color

lyCorrQ = P1D(GrabIObject(treeQ, "/Light_Yield/LY Corr Q").dps)
lyCorrQ.title = "BGO-Q (&gamma;)"
lyCorrQ.style = "p"
lyCorrQ.symbol = 8
lyCorrQ.symbolSize = 16
lyCorrQ.color = colors[1]
lyCorrQ.errY = True
lyCorrQ.errX = False
lyCorrQ.errColor = lyCorrQ.color

lyAlpha = P1D(GrabIObject(treeL, "/Light_Yield/LY alpha").dps)
lyAlpha.title = "BGO - Gironnet et al. (&alpha;)"
lyAlpha.style = "p"
lyAlpha.symbol = 4
lyAlpha.symbolSize = 6
lyAlpha.color = colors[2]
lyAlpha.errAll = False

lyAlphaKey = JaKey(lyAlpha.symbol, lyAlpha.title, 0.2, 0.75, "NDC")
lyAlphaKey.color = lyAlpha.color
lyAlphaKey.keyColor = lyAlpha.color
lyAlphaKey.font = legendFont
lyAlphaKey.penWidth = 2

lyCorrLKey = JaKey(lyCorrL.symbol, lyCorrL.title, 0.2, 0.65, "NDC")
lyCorrLKey.color = lyCorrL.color
lyCorrLKey.keyColor = lyCorrL.color
lyCorrLKey.font = legendFont
lyCorrLKey.penWidth = 2

lyCorrQKey = JaKey(lyCorrQ.symbol, lyCorrQ.title, 0.2, 0.7, "NDC")
lyCorrQKey.color = lyCorrQ.color
lyCorrQKey.keyColor = lyCorrQ.color
lyCorrQKey.font = legendFont
lyCorrQKey.penWidth = 2



lyJaPlotter = HPlotJa("LY Evolution", 600, 600, 1, 1, True)
lyJaPlotter.setGTitle("Light Yield of BGO", titleFont)
lyJaPlotter.antiAlias = False

if showFigures:
	lyJaPlotter.visible(True)
else:
	lyJaPlotter.visible(False)

lyJaPlotter.cd(1, 1)
lyJaPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
lyJaPlotter.setRange(1, 1000, 0, 7)
lyJaPlotter.setLogScale(0, True)
lyJaPlotter.ticFont = ticFont
lyJaPlotter.showStatBox = False
lyJaPlotter.showKey(False)
lyJaPlotter.nameX = "Temperature (K)"
lyJaPlotter.nameY = "LY Normalized to RT (a.u.)"

lyJaPlotter.draw(lyAlpha)
lyJaPlotter.draw(lyCorrL)
lyJaPlotter.draw(lyCorrQ)
lyJaPlotter.add(lyAlphaKey)
lyJaPlotter.add(lyCorrLKey)
lyJaPlotter.add(lyCorrQKey)

theAxes = lyJaPlotter.getPad()
theAxes.setLabelSpace(0, 0.0)
theAxes.setLabelSpace(1, 0.01)

labX = lyJaPlotter.getLabelX()[0][0]
labX.font = axisLabelFont
HPlotJaUtil.setLabelLocationAtCenter(0, labX, lyJaPlotter)
labY = lyJaPlotter.getLabelY()[0][0]
labY.font = axisLabelFont
HPlotJaUtil.setLabelLocationAtCenter(1, labY, lyJaPlotter)


lyJaPlotter.update()

if writeFigures:
	for i in range(len(figType)):
		outFileName = "LY_LQV4" + figType[i]
		lyJaPlotter.export(outPath + File.separator + outFileName)
		print("Writting File : " + outPath + File.separator + outFileName)
		
lyJaPlotter.update()
print("That's all folks !")




